package com.hth.service;

import java.net.*;
import java.io.*;

public class DTYSServer extends Thread {
	
	private ServerSocket serverSocket;

	public DTYSServer(int port) throws IOException {
		serverSocket = new ServerSocket(port);
	}

	public void run() {
		while (true) {
			try {
				System.out.println("Listening on port: " 
						+ serverSocket.getLocalPort() + "...");
				Socket server = serverSocket.accept();
				System.out.println("Just connected to " 
						+ server.getRemoteSocketAddress());
				
				ClientThread clientThread = new ClientThread(server);
				clientThread.start();
			} catch (SocketTimeoutException s) {
				System.out.println("Socket timed out!");
				s.printStackTrace();
				break;
				
			} catch (IOException e) {
				System.out.println("IOException!");
				e.printStackTrace();
				break;
			}
		}
	}
}